package cn.dsscm.service.impl;

import cn.dsscm.dao.ProductCategoryMapper;
import cn.dsscm.dao.ProductMapper;
import cn.dsscm.pojo.ProductCategory;
import cn.dsscm.service.ProductCategoryService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;

@Service("productCategoryService")
@Transactional
public class ProductCategoryServiceImpl implements ProductCategoryService {
    @Resource
    private ProductMapper productMapper;

    @Resource
    private ProductCategoryMapper productCategoryMapper;

    @Override
    public List<ProductCategory> getCategoryByType(Integer type) {
        return productCategoryMapper.getCategoryByType(type);
    }

    @Override
    public List<ProductCategory> getCategoryByParentId(Integer parentId) {
        return productCategoryMapper.getCategoryByParentId(parentId);
    }

    @Override
    public ProductCategory getCategoryById(Integer id) {
        return productCategoryMapper.getCategoryById(id);
    }
    /**
     * 通过ID删除商品（逻辑删除）
     */
    @Override
    @Transactional
    public boolean deleteProductById(Integer delId) {
        try {
            int result = productMapper.deleteProductById(delId);
            return result > 0; // 修复：返回操作是否成功
        } catch (Exception e) {
            throw new RuntimeException("删除商品失败", e);
        }
    }
}